﻿namespace ExamV5.WorkExam
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmMyWorkExamList : Page
    {
        protected GridView DataGridInfo;
        protected HtmlForm Form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        protected Label labRescordCount;
        protected LinkButton LBFirstPage;
        protected LinkButton LBLastPage;
        protected LinkButton LBNextPage;
        protected LinkButton LBPrevPage;
        private PublicFun publicFun_0 = new PublicFun();
        protected ScriptManager SM;
        protected UpdatePanel UPPart;

        protected void DataGridInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.DataGridInfo.PageIndex = e.NewPageIndex;
            this.method_0();
        }

        protected void DataGridInfo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItemIndex == -1)
            {
                this.DataGridInfo.Attributes.Add("oldValue", "#FFFFFF");
                this.DataGridInfo.Attributes.Add("singleValue", "#FFFFFF");
            }
            else
            {
                e.Row.Attributes.Add("onmouseover", "this.bgColor='#F6F5F5'");
                if ((e.Row.DataItemIndex % 2) != 0)
                {
                    e.Row.Attributes.Add("bgcolor", "#FFFFFF");
                    e.Row.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('DataGridInfo').getAttribute('oldValue')");
                }
                else
                {
                    e.Row.Attributes.Add("bgcolor", "#FFFFFF");
                    e.Row.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('DataGridInfo').getAttribute('singleValue')");
                }
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.Cells[1].Text.Length > 10)
                {
                    e.Row.Cells[1].Text = "<a title='" + e.Row.Cells[1].Text + "'>" + e.Row.Cells[1].Text.Substring(0, 10) + "…</a>";
                }
                if (!((this.ViewState["Power"].ToString() == "Y") ? !(this.DataGridInfo.DataKeys[e.Row.RowIndex]["Flag"].ToString() != "A") : true))
                {
                    e.Row.Cells[0].Text = "<a href='FrmLookPaper.aspx?UserCode=" + this.httpCookie_0.Value + "&PaperID=" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperID"].ToString() + "' Target='_blank'>" + e.Row.Cells[0].Text + "</a>";
                }
                Label label = (Label) e.Row.Cells[4].FindControl("labEnter");
                DateTime time2 = Convert.ToDateTime(this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperStartTime"].ToString());
                DateTime time = Convert.ToDateTime(this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperEndTime"].ToString());
                if (DateTime.Now < time2)
                {
                    label.Enabled = false;
                    label.Text = "<a title='试卷有效期：" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperStartTime"].ToString() + "--" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperEndTime"].ToString() + "'>测评时间未到</a>";
                }
                if (DateTime.Now > time)
                {
                    label.Enabled = false;
                    label.Text = "<a title='试卷有效期：" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperStartTime"].ToString() + "--" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperEndTime"].ToString() + "'>测评时间过期</a>";
                }
                string str = this.DataGridInfo.DataKeys[e.Row.RowIndex]["Flag"].ToString().Trim();
                if (str != null)
                {
                    if (str == "A")
                    {
                        e.Row.Cells[3].Text = "未参加测评";
                    }
                    else if (str == "B")
                    {
                        e.Row.Cells[3].Text = "正在测评";
                    }
                    else if (!(str == "C"))
                    {
                        if (str == "G")
                        {
                            e.Row.Cells[3].Text = "异常状态";
                            label.Enabled = false;
                        }
                    }
                    else
                    {
                        e.Row.Cells[3].Text = "测评完成";
                        label.Enabled = false;
                    }
                }
                if (!label.Enabled)
                {
                    label.Enabled = true;
                    if (this.httpCookie_2.Value == "A")
                    {
                        string text1 = this.httpCookie_0.Value;
                        if (this.publicFun_0.GetValues("select LookPaper from UserPower where UserCode='" + this.httpCookie_0.Value + "'", "LookPaper") == "N")
                        {
                            label.Text = "<a href='#' title='查看试卷批改明细权限未开放'><font color=#888888>查看结果</font></font>";
                            return;
                        }
                        label.Text = "<a href='FrmLookPaper.aspx?UserCode=" + this.httpCookie_0.Value + "&PaperID=" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperID"].ToString() + "' Target='_blank'>查看结果</a>";
                    }
                    else
                    {
                        label.Text = "<a href='FrmLookPaper.aspx?UserCode=" + this.httpCookie_0.Value + "&PaperID=" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperID"].ToString() + "' Target='_blank'>查看结果</a>";
                    }
                }
                else
                {
                    label.Text = "<a href='#' title='试卷有效期：" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperStartTime"].ToString() + "--" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperEndTime"].ToString() + "'  onclick=\"javascript:ShowJoinExam('" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["ID"].ToString() + "');\"><font color=red><B>进入测评</B></font></a>";
                }
            }
            if (e.Row.RowType == DataControlRowType.Header)
            {
                if (this.ViewState["SortType"].ToString() == " Desc")
                {
                    switch (this.ViewState["SortFiled"].ToString())
                    {
                        case "ExamName":
                            e.Row.Cells[0].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "SubjectName":
                            e.Row.Cells[1].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "GetCountFen":
                            e.Row.Cells[2].Controls.Add(new LiteralControl("↑"));
                            return;
                    }
                    e.Row.Cells[0].Controls.Add(new LiteralControl("↑"));
                }
                else
                {
                    switch (this.ViewState["SortFiled"].ToString())
                    {
                        case "ExamName":
                            e.Row.Cells[0].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "SubjectName":
                            e.Row.Cells[1].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "GetCountFen":
                            e.Row.Cells[2].Controls.Add(new LiteralControl("↓"));
                            return;
                    }
                    e.Row.Cells[0].Controls.Add(new LiteralControl("↓"));
                }
            }
        }

        protected void DataGridInfo_Sorting(object sender, GridViewSortEventArgs e)
        {
            string sortExpression = e.SortExpression;
            if (this.ViewState["SortFiled"].ToString() == sortExpression)
            {
                if (!(this.ViewState["SortType"].ToString() == " Desc"))
                {
                    this.ViewState["SortType"] = " Desc";
                }
                else
                {
                    this.ViewState["SortType"] = " ASC";
                }
            }
            else
            {
                this.ViewState["SortFiled"] = e.SortExpression;
            }
            this.method_0();
        }

        protected void LBFirstPage_Click(object sender, EventArgs e)
        {
            this.DataGridInfo.PageIndex = 0;
            this.method_0();
        }

        protected void LBLastPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridInfo.PageCount > 0)
            {
                this.DataGridInfo.PageIndex = this.DataGridInfo.PageCount - 1;
                this.method_0();
            }
        }

        protected void LBNextPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridInfo.PageIndex < (this.DataGridInfo.PageCount - 1))
            {
                this.DataGridInfo.PageIndex++;
                this.method_0();
            }
        }

        protected void LBPrevPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridInfo.PageIndex > 0)
            {
                this.DataGridInfo.PageIndex--;
                this.method_0();
            }
        }

        private void method_0()
        {
            string selectCommandText = ("select b.ID,b.PaperStartTime,b.PaperEndTime,a.PaperID,a.ExamName,a.SubjectName,a.GetCountFen,a.Flag from WorkExamUser a,WorkPaperInfo b where a.PaperID=b.ID and a.UserCode='" + this.httpCookie_0.Value + "' ") + " order by " + this.ViewState["SortFiled"].ToString() + this.ViewState["SortType"].ToString();
            SqlConnection selectConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            SqlDataAdapter adapter = new SqlDataAdapter(selectCommandText, selectConnection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet, "DataInfo");
            this.DataGridInfo.DataSource = dataSet.Tables["DataInfo"].DefaultView;
            this.DataGridInfo.DataBind();
            this.labRescordCount.Text = "总共&nbsp;<font color='#0000C0'><b>" + dataSet.Tables["DataInfo"].Rows.Count.ToString() + "</b></font>&nbsp;条记录&nbsp;<font color='#0000C0'><b>" + Convert.ToString((int) (this.DataGridInfo.PageIndex + 1)) + "/" + this.DataGridInfo.PageCount.ToString() + "</b></font>&nbsp;页&nbsp;";
            adapter.Dispose();
            selectConnection.Close();
            selectConnection.Dispose();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) && !(this.httpCookie_0.Value == ""))
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                if (Convert.ToInt32(ConfigurationManager.ConnectionStrings["OnlineNum"].ConnectionString) != 0x3a)
                {
                    if (!base.IsPostBack)
                    {
                        this.publicFun_0.ExecuteSql("delete from Systip where GetNumber='" + this.httpCookie_0.Value + "' and Formtable='WorkPaperInfo'");
                        this.ViewState["Power"] = this.publicFun_0.GetValues("select LookPaper from UserPower where UserCode='" + this.httpCookie_0.Value + "'", "LookPaper");
                        this.Page.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString;
                        this.ViewState["SortFiled"] = "ID";
                        this.ViewState["SortType"] = " Desc";
                        this.method_0();
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheck", "alert('该版本为特惠版，此功能未开放！')", true);
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

